package dao

import (
	"errors"
	"gorm.io/gorm"
	"yun_image/config/image"
	"yun_image/entity"
)

func GetImageShareById(imageShare *entity.ImageShare, id string) error {
	result := DB.Where("id = ? and is_deleted = ?", id, image.NotDeleted).Take(imageShare)
	if errors.Is(result.Error, gorm.ErrRecordNotFound) || result.Error == nil {
		return nil
	}
	return result.Error
}
func CreateImageShare(imageShare *entity.ImageShare) error {
	result := DB.Create(imageShare)
	return result.Error
}

func DeleteImageShare(id string, account string) error {
	result := DB.Model(&entity.ImageShare{}).Where("id = ? and account = ?", id, account).Update("is_deleted", image.Deleted)
	return result.Error
}

func GetImageShareList(list *[]entity.ImageShare, categoryId int) error {
	result := DB.Where("category_id = ? and is_deleted = ?", categoryId, image.NotDeleted).Find(list)
	return result.Error
}
